﻿#include"accountBook.h"
int main()
{
	mysql_init(&mysql);//初始化数据库
	mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, "gbk");//设置编码方式
	if (mysql_real_connect(&mysql, "172.18.5.14", "yeou", "123", "test", 3306, NULL, 0))\
	{
		cout << "数据库连接成功" << endl;
	}
	else
	{
		cout << "数据库连接失败" << endl;
		mysql_error(&mysql);//输出错误信息
	}
	while (1)
	{
		prompt(0);//用户选择
		int exit = 0;
		string sel;
		string in("[1,2,3,4]");//匹配1位整数
		regex rincome(in);
		while (1)
		{
			cout << "请输入相应的操作序号：";
			cin >> sel;
			if (regex_match(sel, rincome))
			{
				break;
			}
			else
			{
				cout << "输入不合法！" << endl;
			}
		}
		int select = stoi(sel);//string 转换int
		int ifLogin = 0;
		int ifLogon = 0;
		switch (select)
		{
		case 1:ifLogin = login(); break;
		case 2:ifLogon = logon(); break;
		case 3:; break;
		case 4:; break;
		default: cout << "输入错误，请重新输入" << endl;
		}
		if (select == 1)//登录结果
		{
			while (1)
			{
				if (ifLogin == 1)//登录成功
				{
					cout << "\n\n\n\n---------";
					sprintf_s(query, "select id,name from user where account='%s'", account);//查找当前用户id 用户名，并输出
					inquiry(query, 1);
					prompt(1);//显示可执行的系统操作
					select = 0;
					cout << "请输入相应的操作序号：";
					while (!(cin >> select))
					{
						cin.clear();
						while (cin.get() != '\n')
							continue;
						cout << "输入错误，请重新输入:";
					}
					switch (select)
					{
					case 1:cout << "\n收入系统：\n"; if (incomes() == 1) { cout << "记录成功" << endl; }
						  else { cout << "记录失败"; } break;
					case 2:cout << "\n支出系统：\n"; if (expenses() == 1) { cout << "记录成功" << endl; }
						  else { cout << "记录失败"; } break;
					case 3:cout << "\n修改收入："; updateIncomes(); break;
					case 4:cout << "\n修改支出："; updateExpenses(); break;
					case 5:cout << "\n储蓄系统：" << endl; seeSave(); break;
					case 6:cout << "\n个人信息：" << endl; seeUser(); break;
					case 7:cout << "\n账单统计：" << endl; billingStatistics(); break;
					case 8:cout << "\n退出登录：" << endl; 
					{
						if (exitSystem(0) == 1) { exit=1; }
						else break;
					}
					default:break;
					}
				}
				else
				{
					cout << "登录失败" << endl; break;
				}
				if (exit == 1)break;
				else;
			}
		}
		else if (select == 2)//注册结果
		{
			if (ifLogon == 1)
			{
				cout << "注册成功" << endl;
			}
			else
			{
				cout << "注册失败" << endl;
			}
		}
		else if (select == 3)//找回密码
		{
			forgotPassword();
		}
		else
		{
			if (exitSystem(1) == 1) { break; }
			else ;
		}
	}
	mysql_free_result(res);//释放结果集
	mysql_close(&mysql);//关闭数据库*/
}